#include <iostream>
#include <list>
#include "vector.h"

using namespace std;

template<class T>
void f(){
    T x = T();
    cout << x << endl;
}

void test1(){
    int i = int();
    int j = int(1);
}

void test2(){
    f<int>();
    f<int*>();
    f<double>();
}

void test3(){
    int i = 1;
    const int& j = i;
    i = 2;
    cout << i << endl;
    cout << j << endl;
}

class A{
public:
    A(){
        cout << "A()" << endl;
    }

    ~A(){
        cout << "~A()" << endl;
    }
};

void test4(){
    A a1;
    A();
    A a2;
}

void test5(){
    A a1;
    //const A& xx = A();
    A xx = A();
    A a2;
}

void test6(){
    string s1("hello");
    cout << s1 << endl;
}

void list_test1(){
    list<int> lt;
    lt.push_back(1);
    lt.push_back(2);
    lt.push_back(3);
    lt.push_back(4);
    auto it = lt.begin();
    while (it != lt.end()){
        cout << *it << " ";
        ++it;
    }
    cout << endl;
    auto pos = find(lt.begin(), lt.end(), 3);
    if (pos != lt.end())
        lt.insert(pos, 9);
    for (auto pc : lt) {
        cout << pc << " ";
    }
    cout << endl;
}

void list_test2(){
    list<int> lt;
    lt.push_back(10);
    lt.push_back(2);
    lt.push_back(5);
    lt.push_back(3);
    lt.push_back(4);
    lt.push_back(4);
    lt.push_back(6);
    lt.push_back(4);
    lt.push_back(0);
    for (auto e : lt)
        cout << e << " ";
    cout << endl;
    lt.sort();
    // 迭代器功能分类
    // 1、单向  ++
    // 2、双向  ++  --
    // 3、随机  ++  --  +  -
    //sort(lt.begin(), lt.end());
    for (auto e : lt)
        cout << e << " ";
    cout << endl;
}

void list_test3(){
    srand(time(nullptr));
    const int N = 1000000;
    vector<int> v;
    v.reserve(N);

    list<int> lt1;
    list<int> lt2;
    for (int i = 0; i < N; ++i) {
        auto e = rand();
        lt1.push_back(e);
        lt2.push_back(e);
    }

    //拷贝到vector里sort
    int begin1 = clock();
    for (auto e : lt1) {
        v.push_back(e);
    }
    sort(v.begin(), v.end());
    size_t i = 0;
    for (auto e : lt1) {
        e = v[i++];
    }
    int end1 = clock();

    //在list中直接sort
    int begin2 = clock();
    lt2.sort();
    int end2 = clock();

    cout << end1 - begin1 << endl;
    cout << end2 - begin2 << endl;
}

int main() {
    Lu::Test14();
    //test6();
    //list_test3();
    return 0;
}
